package com.gomtel.smartdevice.ui.activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.gomtel.smartdevice.R;
import com.gomtel.smartdevice.base.WatchAppBaseActivity;
import com.gomtel.smartdevice.global.WatchApplication;
import com.gomtel.smartdevice.moudle.event.CommonEvent;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/5/14 0014.
 */

public class WelComeActivity extends WatchAppBaseActivity implements View.OnClickListener {

    @BindView(R.id.text_login)
    TextView text_login;
    private int ss = 3;
    private boolean status = true;

    private Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            if (text_login != null) {
                text_login.setText(String.valueOf(ss));
            }
            return true;
        }
    });


    @Override
    protected void registerEvent(CommonEvent commonevent) {

    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_welcome;
    }

    @Override
    protected void initClass() {
        ssOrRun();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {
        text_login.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.text_login:
                status = false;
                startActivity(new Intent(WelComeActivity.this, LoginActivity.class));
                finish();
                break;
        }
    }

    private void ssOrRun() {
        WatchApplication.executorService.submit(() -> {
            try {
                Thread.sleep(999);
                handler.sendEmptyMessage(0);
                ss--;
                if (ss > 0) {
                    ssOrRun();
                } else {
                    if (status) {
                        startActivity(new Intent(WelComeActivity.this, LoginActivity.class));
                        finish();
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
    }
}
